package com.lc.qianrenshiye.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lc.qianrenshiye.BaseActivity;
import com.lc.qianrenshiye.BaseApplication;
import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.conn.BusinessCenterLoginPost;
import com.lc.qianrenshiye.uitls.MyToast;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilMD5;

/**
 * Created by shenyuxin on 2016/11/16.
 */
public class BusinessCenterLoginActivity extends BaseActivity implements View.OnClickListener{

    @BoundView(R.id.business_login_password_et) private EditText business_login_password_et;
    @BoundView(R.id.business_login_forget_password_tv) private TextView business_login_forget_password_tv;
    @BoundView(R.id.business_login_submit_tv) private TextView business_login_submit_tv;

    private BusinessCenterLoginPost businessCenterLoginPost = new BusinessCenterLoginPost(new AsyCallBack<String>() {

        @Override
        public void onSuccess(String toast, int type, String s) throws Exception {

            MyToast.showToast(toast, context);

            BaseApplication.BasePreferences.saveServiceTel(s);

            startActivity(new Intent(BusinessCenterLoginActivity.this, BusinessCenterActivity.class));

            finish();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.showToast(toast, context);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_center_login);

        setBackTrue();

        setTitleName(getString(R.string.business_center_title_text));


        business_login_forget_password_tv.setOnClickListener(this);
        business_login_submit_tv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.business_login_forget_password_tv:

                startActivity(new Intent(this, ChangePasswordActivity.class));

                break;

            case R.id.business_login_submit_tv:

                if (TextUtils.isEmpty(getPassword())) {

                    MyToast.showToast(getString(R.string.please_fill_password_hint), context);

                    return;
                }

                businessCenterLoginPost.uid = BaseApplication.BasePreferences.readUserId();
                businessCenterLoginPost.password = UtilMD5.MD5Encode(UtilMD5.MD5Encode(getPassword(), "UTF-8"), "UTF-8");

                businessCenterLoginPost.execute(this);

                break;

        }

    }

    private String getPassword() {

        return business_login_password_et.getText().toString().trim();
    }

}
